package com.zhongkai.controller;

import com.zhongkai.app.service.DeviceControlService;
import com.zhongkai.model.utils.ZhongkaiResult;
import com.zhongkai.model3.Chinaset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class DeviceControlController {

    @Autowired
    private DeviceControlService appRegLogService;

/*    @Autowired
    private LoginInterceptor loginInterceptor;*/


    /**
     * 通电吧 皮卡丘
     * 断电吧 皮卡丘
     * web页面控制设备
     *
     * @param device_id 设备uuid
     * @param is_switch 命令 1 开机  2关机 3 改变温度
     * @param parameter 非必传
     */
    @RequestMapping(value = "/unit/switch", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult device_switch( String device_id, String is_switch, Integer parameter,HttpServletRequest httpServletRequest) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
      //  System.out.println(chinaset.getUuid());
        ZhongkaiResult result = null;
        try {
            result = appRegLogService.device_switch(device_id, is_switch, parameter,chinaset.getUuid());
        } catch (Exception e) {
            e.printStackTrace();

            return ZhongkaiResult.build(500,"失败");
        }

        return result;
    }
}
